package com.林子祺.CAT旅游系统.dao.deal;

import com.林子祺.CAT旅游系统.entity.login.LoginStatus;

import java.sql.*;
import java.text.SimpleDateFormat;

public class ChargeMoney {

    public static void Charge(double money){
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   //用上面字母表示时间，但是其他的可以变
        String d = sdf.format(new Date(System.currentTimeMillis()));            //对上面给定的模式进行格式化

        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/travelsys", "root", "@Blink102417");

            double last = LoginStatus.money + money;

            String sql1 = "update user set money = "+"'"+ last +"'"+" where name = "+"'"+LoginStatus.name+"'";

            stmt = conn.createStatement();

            stmt.execute(sql1);

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            if(rs != null) {
                try {
                    rs.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if(stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if(conn != null) {
                try {
                    conn.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }
    }

}
